package com.google.code.head2head.gwtmodules.client.imagepanels;

import java.util.Iterator;
import java.util.List;

import com.google.code.head2head.gwtmodules.client.dto.EntryDto;
import com.google.code.head2head.gwtmodules.client.services.UserInfoService;
import com.google.code.head2head.gwtmodules.client.services.UserInfoServiceAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;

public class AllEntriesPanel extends FlowPanel {

	private List entries;

	public AllEntriesPanel() {

		UserInfoServiceAsync svc = (UserInfoServiceAsync) GWT
				.create(UserInfoService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) svc;
		String moduleRelativeURL = GWT.getModuleBaseURL()
				+ "../userInfoService";
		endpoint.setServiceEntryPoint(moduleRelativeURL);

		AsyncCallback callback = new AsyncCallback() {

			public void onSuccess(Object result) {
				entries = (List) result;

				for (Iterator iterator = entries.iterator(); iterator.hasNext();) {
					EntryDto entry = (EntryDto) iterator.next();
					add(new DisclosureTwoImagePanel(entry.getFistImageUrl(), entry.getSecondImageUrl()));
					add(new HTML("      "));
				}
			}

			public void onFailure(Throwable ex) {
				Window.alert("Problem loading images directories");
			}
		};
		// execute the service
		svc.getAllEntries(callback);
		

	}

}

